//
//  XTNavigationController.m
//  MSBCooperateTest
//
//  Created by xtxk3 on 15/1/12.
//  Copyright (c) 2015年 xtxk1. All rights reserved.
//

#import "QRNavigationController.h"

#define BACK_BTN_FRAME CGRectMake(0.0f, 0.0f, 40.0f, 40.0f)

@implementation QRNavigationController

- (id)initWithRootViewController:(UIViewController *)rootViewController
{
    self = [super initWithRootViewController:rootViewController];
    if (self)
    {
        UIColor * color = [UIColor whiteColor];
        UIFont * font = [UIFont boldSystemFontOfSize:17.0];
        NSDictionary * dict = @{NSForegroundColorAttributeName:color,NSFontAttributeName:font};
        self.navigationBar.titleTextAttributes = dict;
        self.navigationBar.translucent = NO;
        [self.navigationBar setBarTintColor:[UIColor blackColor]];
    }
    return self;
}

//返回上层界面
-(void)popself
{
    [self popViewControllerAnimated:YES];
}

//自定义返回按钮
-(UIBarButtonItem*) createBackButton
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setFrame:BACK_BTN_FRAME];
    [button addTarget:self action:@selector(popself) forControlEvents:UIControlEventTouchUpInside];
//    [button setImage:[UIImage imageNamed:@"backView"] forState:UIControlStateNormal];
    
    UIBarButtonItem *leftitem = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    UIImageView * backView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 8, 14, 22)];
    backView.image = [UIImage imageNamed:@"navigationBack"];
    
    [button addSubview:backView];
    return leftitem;
}

//push进入下一层界面
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        
        if ([viewController isKindOfClass:[UITabBarController class]]) {
            self.interactivePopGestureRecognizer.enabled = NO;
        }else{
            self.interactivePopGestureRecognizer.enabled = YES;
        }
    }
    
    [super pushViewController:viewController animated:animated];
    
    if (viewController.navigationItem.leftBarButtonItem == nil && [self.viewControllers count] > 1) {
        viewController.navigationItem.leftBarButtonItem =[self createBackButton];
        
    }
//    if (![viewController isKindOfClass:[UITabBarController class]]) {
//        //开启iOS7的滑动返回效果
//        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//            self.interactivePopGestureRecognizer.delegate = nil;
//        }
//    }
}


@end

@implementation UINavigationItem (margin)

@end

@implementation UINavigationController (Rotation)

@end
